/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package org.swirrel.listener;

import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;

import org.swirrel.util.MethodCall;
import org.swirrel.util.SwirrelException;

/**
 *
 * @author Gronau
 */
public class SwirrelMouseListener
    extends AbstractSwirrelListener implements MouseListener {

  private final MethodCall mouseClickedCall;
  private final MethodCall mousePressedCall;
  private final MethodCall mouseReleasedCall;
  private final MethodCall mouseEnteredCall;
  private final MethodCall mouseExitedCall;

  public SwirrelMouseListener(
      MethodCall mouseClickedCall,
      MethodCall mousePressedCall,
      MethodCall mouseReleasedCall,
      MethodCall mouseEnteredCall,
      MethodCall mouseExitedCall) {
    this.mouseClickedCall = mouseClickedCall;
    this.mousePressedCall = mousePressedCall;
    this.mouseReleasedCall = mouseReleasedCall;
    this.mouseEnteredCall = mouseEnteredCall;
    this.mouseExitedCall = mouseExitedCall;
    if ( !checkSignature(mouseClickedCall, MouseEvent.class) ||
         !checkSignature(mousePressedCall, MouseEvent.class) ||
         !checkSignature(mouseReleasedCall, MouseEvent.class) ||
         !checkSignature(mouseEnteredCall, MouseEvent.class) ||
         !checkSignature(mouseExitedCall, MouseEvent.class)) {
      throw new SwirrelException(
          "Method must have none or one MouseEvent argument");
    }
  }

  public void mouseClicked(MouseEvent e) {
    call(mouseClickedCall, e);
  }

  public void mousePressed(MouseEvent e) {
    call(mousePressedCall, e);
  }

  public void mouseReleased(MouseEvent e) {
    call(mouseReleasedCall, e);
  }

  public void mouseEntered(MouseEvent e) {
    call(mouseEnteredCall, e);
  }

  public void mouseExited(MouseEvent e) {
    call(mouseExitedCall, e);
  }
}
